<template>
  <div class="my-container" >
       <div class="userInfo header" v-if="user">
  <!-- 基本信息 -->
  <div class="base">
    <div class="left">
      <van-image
                 fit="cover"
                 :src="userinfo.photo"
                 class="avatar"
                 round
                 />
      <span class="name">{{userinfo.name}}</span>
    </div>
    <div class="right">
      <van-button type="default" size="mini" round to="/userprofile">编辑资料</van-button>
    </div>
  </div>
  <!-- 粉丝、关注 -->
   <div class="data">
        <div class="data-item">
          <span class="count"></span>
          <span class="text">头条</span>
        </div>
        <div class="data-item">
          <span class="count"></span>
          <span class="text">关注</span>
        </div>
        <div class="data-item">
          <span class="count"></span>
          <span class="text">粉丝</span>
        </div>
        <div class="data-item">
          <span class="count"></span>
          <span class="text">获赞</span>
        </div>
      </div>
</div>
      <div class="header not-login" v-else>
      <div class="login-btn" @click="$router.push('/login')">
        <img class="mobile-img" src="~@/assets/mobile.png" alt="">
        <span class="text">登录 / 注册</span>
      </div>
    </div>
    <van-grid class="grid-nav mb-9" :column-num="2" clickable>
      <van-grid-item class="grid-item">
        <i slot="icon" class="toutiao toutiao-shoucang"></i>
        <span slot="text" class="text">收藏</span>
      </van-grid-item>
      <van-grid-item class="grid-item">
        <i slot="icon" class="toutiao toutiao-lishi"></i>
        <span slot="text" class="text">历史</span>
      </van-grid-item>
    </van-grid>
    <div class="grid-nav"></div>
    <van-cell title="消息通知" is-link url="" />
    <van-cell title="小智同学" is-link url="" />
     <van-cell class="logout-cell" title="退出登录" @click="outBtn"/>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { getUserInfo } from '@/api/user.js'
export default {
  name: 'MyIndex',
  components: {},
  props: {},
  data () {
    return {
      userinfo: {}
    }
  },
  computed: {
    ...mapState(['user'])
  },
  watch: {},
  created () {
    if (this.user) {
      this.loadUser()
    }
  },
  mounted () {},
  methods: {
    outBtn () {
      this.$dialog.confirm({ title: '确认退出吗' }).then(() => {
        this.$store.commit('setUser', null)
      }).catch(() => {})
    },
    async loadUser () {
      try {
        const res = await getUserInfo()
        console.log(res)
        this.userinfo = res.data.data
      } catch (err) {
        console.log(err)
        this.$toast('获取数据失败')
      }
    }
  }
}
</script>

<style scoped lang="less">
.my-container {
  .not-login {
    display: flex;
    justify-content: center;
    align-items: center;
    .login-btn {
      display: flex;
      flex-direction: column;
      align-items: center;
      .mobile-img {
        width: 132px;
        height: 132px;
        margin-bottom: 15px;
      }
      .text {
        font-size: 28px;
        color: #fff;
      }
    }
  }   justify-content: center;
.header {
    width: 750px;
    height: 401px;
    background: url('~@/assets/banner.png');
    background-size: cover;
  }
.userInfo {
    .base {
      height: 231px;
      padding: 76px 32px 23px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-sizing: border-box;
      .left {
        display: flex;
        align-items: center;
        .avatar {
          width: 132px;
          height: 132px;
          border: 4px solid #fff;
          margin-right: 23px;
        }
        .name {
          font-size: 29px;
          color: #fff;
        }
      }
    }
    .data {
  display: flex;
  justify-content: space-around;
  .data-item {
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
    span:nth-child(1) {
      font-size: 36px;
      margin-bottom: 15px;
    }
    span:nth-child(2) {
      font-size: 23px;
    }
  }
}
  }
  .grid-nav {
    .grid-item {
      height: 141px;
      i.toutiao {
        font-size: 45px;
      }
      .toutiao-shoucang {
        color: #eb5253;
      }
      .toutiao-lishi {
        color: #ff9d1d;
      }
      span.text {
        font-size: 28px;
      }
    }
  }
   .logout-cell {
    text-align: center;
    color: #d86262;
  }
}

</style>
